/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.freedom.railhunter.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.freedom.railhunter.model.Station;
import org.slf4j.LoggerFactory;

/**
 *
 * @author Alan
 */
public class StationManager {
    
     private static final org.slf4j.Logger logger = LoggerFactory.getLogger(StationManager.class);
     
     public static final Map<String, Station> NAME_STATION_MAP = new HashMap<>();
     
     public static final Map<String, Station> TELECODE_STATION_MAP = new HashMap<>();
     
     static {
         readStationNames();
     }
    
     /**
      * 读取所有的站点名称以及车次编号
      */
    private static void  readStationNames() {
        Properties properties = new Properties();
        try {
            properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("station_names.properties"));
            String stationNames = properties.getProperty("station_names");
            String[] staionNameInfoArray = stationNames.split("@");
            for (String staionNameInfo : staionNameInfoArray) {
                if (StringUtils.isNotEmpty(staionNameInfo)) {
                    String[] info = staionNameInfo.split("\\|");
                    Station staion = new Station();
                    staion.setName(info[1]);
                    staion.setTelecode(info[2]);
                    staion.setPinyin(info[3]);
                    staion.setSimplePinyin(info[4]);
                    NAME_STATION_MAP.put(info[1], staion);
                    TELECODE_STATION_MAP.put(info[2], staion);
                }
            }
        } catch (FileNotFoundException ex) {
            logger.error(null, ex);
        } catch (IOException ex) {
            logger.error(null, ex);
        }
    }
    
    public static void main(String[] args) throws Exception {
        String s = "passengerTicketStr=1%2C0%2C1%2C%E5%88%98%E6%95%8F%2C1%2C430422198603156239%2C13564227366%2CN&oldPassengerStr=%E5%88%98%E6%95%8F%2C1%2C430422198603156239%2C1_&randCode=uqr8&purpose_codes=ADULT&key_check_isChange=DD9AE493643FB7A5119318D2F061B2084D1453CB56CDB0BB4BEAF4D2&leftTicketStr=1015653331404405000010156500383027950001&train_location=H2&_json_att=";
        //System.out.println(s.length());
        
        String n = "%E5%88%98%E6%95%8F%2C1%2C430422198603156239%2C1_";
        System.out.println(URLEncoder.encode(n, "utf-8"));
    }
}
